package com.lumlord.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lumlord.model.custom.TableSplitResult;
import com.lumlord.model.custom.Page;
import com.lumlord.service.AutoCodeService;
import com.lumlord.common.annotation.Api;
import com.lumlord.common.base.ApiController;
import com.lumlord.common.domain.User;
import com.lumlord.common.exception.BusinessException;
import com.lumlord.mapper.auto.AutoCode;



/**
 * 自动代码生成 AutoCode 
 * @author gpf
 * @email 372138617@qq.com
 * @date 2019-09-23 12:45:51
 */
@Controller
@Api(moduleName = "自动代码生成",NameSpace = "/")
public class AutoCodeController extends ApiController{
	 
	@Api(actionName = "自动代码生成集合查询", method = RequestMethod.POST, path = "/abv")
	public Object abc(Page page) throws BusinessException{
		 
		
		return  "22";
	}
	
	@Api(actionName = "自动代码生成集合查询", method = RequestMethod.POST, path = "/autoCodes")
	public Object query(Page page,User user) throws BusinessException{
		PageInfo<AutoCode> data =autoCodeService.list(page) ;
		TableSplitResult<AutoCode> result=new TableSplitResult<AutoCode>(data.getPageNum(), data.getTotal(), data.getList());
		System.out.println(user);





		return  user;
	}
	
	@Api(actionName = "自动代码生成根据主键获取内容", method = RequestMethod.GET, path = "/autoCode/{id}")
	public Object get(Integer id) throws BusinessException{
		return  autoCodeService.selectByPrimaryKey(id);
	}
	 
	

	@Api(actionName = "自动代码生成新增", method = RequestMethod.POST, path = "/autoCode")
	public Boolean add(AutoCode autoCode,Model model)throws BusinessException{
		int b=autoCodeService.insertSelective(autoCode);
		if(b>0){
			return true;
		}else{
			return false;
		}
	}
	
	
	@Api(actionName = "自动代码生成修改", method = RequestMethod.POST, path = "/autoCode/{id}")
	public Boolean update(AutoCode autoCode)throws BusinessException{
		int b=autoCodeService.insertSelective(autoCode);
		if(b>0){
			return true;
		}else{
			return false;
		}
	}
	
	 
	@Api(actionName = "自动代码生成逻辑删除", method = RequestMethod.DELETE, path = "/autoCode",isAllow = true)
	public Boolean remove(Integer[] ids) throws BusinessException{
		int b=autoCodeService.del(ids);
		if(b>0){
			return true;
		}else{
			return false;
		}
	}
	
	 
	/**
     	* 新增或修改自动代码生成
     */
    @Api(actionName = "自动代码生成新增或修改", method = RequestMethod.PUT, path = "/autoCode")
    public Boolean saveAndUpdate(AutoCode record)throws BusinessException{	
    	int b=autoCodeService.updateByPrimaryKeySelective(record);
		if(b>0){
			return true;
		}else{
			return false;
		}
    }
    
	@Autowired
	private AutoCodeService autoCodeService;
}
